package com.centaline.androidsalesblog.rx.database;

import com.centaline.androidsalesblog.constants.AppConstant;
import com.centaline.androidsalesblog.model.databaseobject.HistoryContactDo;
import com.centaline.androidsalesblog.model.databaseobject.StaffDo;

import org.litepal.crud.DataSupport;

import rx.Observable;
import rx.Subscriber;

/**
 * 删除最近联系人
 * Created by guilin on 16/3/14.
 */
public class HistoryStaffsDeleteOnSubscribe implements Observable.OnSubscribe<Boolean> {

    private final StaffDo staffDo;

    public HistoryStaffsDeleteOnSubscribe(StaffDo staffDo) {
        this.staffDo = staffDo;
    }

    @Override
    public void call(Subscriber<? super Boolean> subscriber) {
        DataSupport.deleteAll(HistoryContactDo.class, "cityCode = ? and staffNo = ?",
                AppConstant.CityCode, staffDo.getStaffNo());
        if (!subscriber.isUnsubscribed()) {
            subscriber.onNext(true);
        }
        subscriber.onCompleted();
    }
}
